package cn.wzptsoft.mall.controller;

import cn.wzptsoft.mall.pojo.Spu;
import cn.wzptsoft.mall.pojo.dto.PageDto;
import cn.wzptsoft.mall.pojo.dto.PutOrderDTO;
import cn.wzptsoft.mall.pojo.vo.AddressInfoVO;
import cn.wzptsoft.mall.pojo.result.Result;
import cn.wzptsoft.mall.pojo.vo.OrderInfoVO;
import cn.wzptsoft.mall.pojo.vo.PageVo;
import cn.wzptsoft.mall.service.IAddressService;
import cn.wzptsoft.mall.service.IOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Slf4j
@Tag(name = "购物车相关接口")
@RequiredArgsConstructor
public class OrderController {
    private final IOrderService orderService;

    private final IAddressService addressService;

    @PostMapping("/add")
    @Operation(summary = "提交订单")
    public Result add(@RequestBody PutOrderDTO putOrderDTO){
        orderService.add(putOrderDTO);
        return Result.ok();
    }

    @GetMapping("/getAddress")
    @Operation(summary = "查询地址簿")
    public Result<List<AddressInfoVO>> getUserAddress(){
        List<AddressInfoVO> vo= addressService.getUserAddress();
        return Result.ok(vo);

    }


    @PostMapping("/list")
    @Operation(summary = "查询订单数据")
    public Result<PageVo<OrderInfoVO>> list(@RequestBody PageDto pageDto){
        PageVo<OrderInfoVO> vo= orderService.getDetail(pageDto.getStart(),pageDto.getCount());
        return Result.ok(vo);

    }






}
